unit Thrad_GetCount;

interface

uses
  Classes,SysUtils,Class_KzThrad,Uni,UniConnct,UniConfig,Unit1,SyncObjs;

type
  TThradGetCount = class(TKzThrad)
  public
    FUniConfig:TUniConfig;
    FQueryRect:TQueryRect;
    FQueryNumb:Integer;

    FCS:TCriticalSection;
  protected
    procedure Execute; override;
  end;

implementation
uses
  ActiveX;

{ TThradGetCount }

procedure TThradGetCount.Execute;
var
  I:Integer;
  SQLA:string;
  NumbA:Integer;

  UniConnct:TUniConnection;
begin
  CoInitialize(nil);

  if FCS<>nil then
  begin
    FCS.Enter;
  end;
  
  FQueryNumb:=0;
  try
    UniConnct:=UniConnctEx.GetConnection(FUniConfig);
    //-<
    GetMaxProgress(FQueryRect.ENDVAL);
    for I:=FQueryRect.STAVAL to FQueryRect.ENDVAL do
    begin
      SQLA:='SELECT COUNT(*) AS NUMB FROM TBL_WAGE_FL WHERE (FIELD%D <> %S ) AND (FIELD%D <>%S)';
      SQLA:=Format(SQLA,[I,QuotedStr(''),I,QuotedStr('0')]);

      NumbA:=TUniConnct.CheckField(SQLA,'NUMB',UniConnct);

      FQueryNumb:=FQueryNumb+NumbA;

      Sleep(0);
      GetOneProgress(I);
    end;

    GetMsgProgress('FILL.GRID',[FQueryRect.GROUPX,FQueryNumb]);
    GetMaxProgress(0);
    GetOneProgress(0);
    //->
  finally
    FreeAndNil(UniConnct);
  end;

  if FCS<>nil then
  begin
    FCS.Leave;
  end;
  
  CoUninitialize;
end;

end.
